<template>
  <div class="artist-data">
    <el-card
      class="table-card header_boder_bottom artist_tabel_box"
      shadow="never"
    >
      <!-- 列表搜索 -->
      <div class="sreach-box">
        <Add
          v-if="$GLOBAL.includes('/menu/add')"
          ref="addDrama"
          style="height: 32px"
          @close="closeAdd"
        ></Add>
        <p v-else></p>
      </div>

      <div v-if="data" v-loading="tableLoading" class="tab_box">
        <XgmTable
          ref="artistTable"
          :columns.sync="columnsShow"
          :data="data"
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          @selectionChange="selectionChange"
          @sortChange="sortChange"
        >
          <!-- 高亮表头 -->
          <template
            v-for="(prop, i) in redTable"
            :slot="`header-${prop}`"
            slot-scope="{ label }"
          >
            <span :key="i">
              <span style="color: red">{{ label }}</span>
            </span>
          </template>
          <template slot="is_menu" slot-scope="{ scope }">
            <span>
              <el-tag v-if="scope.row.is_menu == 1">菜单</el-tag>
              <el-tag v-else type="info">功能</el-tag>
            </span>
          </template>
          <template slot="edit" slot-scope="{ scope }">
            <div class="edit-box">
              <el-button
                v-if="$GLOBAL.includes('/menu/edit')"
                type="primary"
                class="bg-6BD9BA"
                @click="handle_look(scope.row)"
              >
                编辑
              </el-button>
              <el-button
                v-if="$GLOBAL.includes('/menu/delete')"
                class="bg-6BD9BA"
                type="danger"
                @click="deleteMenu(scope.row)"
              >
                删除
              </el-button>
            </div>
          </template>
        </XgmTable>
      </div>
    </el-card>
  </div>
</template>
<script>
  let columns = [
    {
      label: '菜单名称',
      prop: 'name',
      showOverflowTooltip: false,
      width: 'auto',
    },
    {
      label: '路径',
      prop: 'path',
      showOverflowTooltip: false,
    },
    {
      label: '图标',
      prop: 'icon',
      showOverflowTooltip: false,
    },
    {
      label: '类型',
      prop: 'is_menu',
      showOverflowTooltip: false,
    },
    {
      label: '排序',
      prop: 'sort',
      width: '100',
      showOverflowTooltip: false,
    },
    {
      label: '操作',
      prop: 'edit',
      fixed: 'right',
      width: '180',
      showOverflowTooltip: true,
    },
  ]
  import { allMenu, deleteMenu } from '@/api/admin.js'
  import XgmTable from '@/components/XgmTable'
  import Add from './components/addMenu.vue'
  export default {
    name: 'RecommendList',
    components: { XgmTable, Add },
    props: {},
    data() {
      return {
        data: [],
        columns,
        redTable: [],
        pagination: {
          total: 0,
          page: 1,
          pageSize: 20, //每页中显示10条数据
          pageSizeS: [10, 20, 40],
          showTotal: (total) => `共有 ${total} 条数据`,
        },
        sort: {
          order_type: 'desc', // 'desc ,
          order_key: 'update_time',
        },
        tableLoading: false,
      }
    },
    computed: {
      columnsShow: {
        get() {
          return this.columns
        },
        set(val) {
          this.exportColumns = val.filter((item) => item.prop != 'edit')
        },
      },
      orderBy() {
        return {
          [this.sort.order_key]: this.sort.order_type,
        }
      },
      // 选中的数据id
      ids() {
        return this.seltTableData.map((item) => item.id)
      },
    },
    watch: {
      // 监听筛选的数据
      screenData(data) {
        this.pagination.page = 1
        this.getAllMenu()
      },
    },
    async created() {
      // 列表
      this.getAllMenu()
    },
    methods: {
      async getAllMenu() {
        if (!this.$GLOBAL.includes('/menu/tree')) return
        this.tableLoading = true
        let data = await allMenu()
        if (data.code == 1) {
          this.data = data.data
        }
        this.tableLoading = false
      },
      closeAdd(e) {
        if (e) {
          this.getAllMenu()
        }
      },
      handle_look(item) {
        this.$refs.addDrama.applynewadd(item)
      },
      async deleteMenu(item) {
        this.$confirm('是否继续此操作?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            let params = { id: item.id }
            let data = await deleteMenu(params)
            if (data.code == 1) {
              this.$baseMessage('操作成功', 'success')
              setTimeout(() => {
                this.getAllMenu()
              }, 1000)
            }
          })
          .catch(() => {})
      },
      selectionChange(selection) {
        this.seltTableData = selection
      },
      handleChange() {},
      // 排序 order是降序或者升序 prop是字段
      sortChange({ order, prop }) {
        this.sort.order_type = {
          ascending: 'asc',
          descending: 'desc',
        }[order]
        this.sort.order_key = prop
        this.pagination.page = 1
        this.getAllMenu()
      },
    },
  }
</script>
<style lang="scss" scoped>
  .df {
    display: flex;
    align-items: center;
  }
  .edit-box {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .page-footer {
    position: sticky;
    bottom: 0;
    padding: 0 14px 14px;
    background-color: #fff;
    z-index: 10;
  }

  p {
    margin-bottom: 0;
  }

  .contract-tip-box {
    width: 150px;
    word-break: break-all;

    > p {
      margin-bottom: 4px;
      font-size: 12px;
    }
  }
  .account-user-box {
    display: flex;
    justify-content: space-between;
    word-break: break-all;
    background-color: #fff;
    padding: 14px 10px;
    border-radius: 10px;
    overflow: hidden;

    .head_img_box {
      position: relative;
      width: 40px;
      height: 40px;
      overflow: hidden;

      .head_img {
        width: 100%;
        height: 100%;
        border-radius: 40px;
      }

      .platform_path {
        position: absolute;
        bottom: -6px;
        right: 0;
        width: 14px;
      }
    }

    .user-text {
      margin-left: 10px;
      flex: 1;

      p {
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 17px;

        display: flex;
        justify-content: space-between;
        margin-bottom: 6px;
      }

      .anchor_name {
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #2a304d;
        line-height: 20px;
      }

      .anchor_id {
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #8895a4;
        line-height: 17px;
        margin-bottom: 8px;
      }
    }
  }

  .acc_msg {
    display: flex;

    .account-table-box {
      display: grid;
      grid-template-columns: 1fr 1fr;
      grid-gap: 10px;
      grid-row: 10px;

      .account-box {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100px;

        .account-item {
          color: #3f8cff;
          font-size: 14px;
          padding: 2px 12px;
          line-height: 20px;
          white-space: nowrap;
          display: inline-block;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;

          background: #f1f7ff;
          border-radius: 2px;
          border: 1px solid #3a90ff;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
        }
      }
    }
  }

  .artist-data {
    padding: 10px 10px 0;
    min-height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;

    ::v-deep.ant-spin-nested-loading {
      background-color: #fff;
      flex: 1;
    }

    p {
      margin-bottom: 0;
    }

    .sreach-box {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: white;
      border-radius: 5px;
      margin-bottom: 20px;

      .line {
        background: #dfdfe1;
        width: 1px;
        height: 30px;
        display: inline-block;
      }

      > p {
        font-size: 14px;
        color: #333333;
      }
    }

    .screen-box {
      background-color: white;
      padding: 20px 15px 0px 15px;
      display: flex;
      align-items: flex-end;
      justify-content: space-between;

      .screen-left-box {
        flex: 1;
      }

      .item {
        display: flex;
        align-items: flex-start;
        padding-bottom: 16px;

        &:last-child {
          padding-bottom: 0px;
        }

        .tag-box {
          display: flex;
          align-items: center;
          flex-wrap: wrap;

          .screen-tag {
            cursor: pointer;
            line-height: 22px;
            padding: 0 9px;
            margin-right: 10px;
            color: #333333;
            border-radius: 2px;
            margin-bottom: 4px;

            font-size: 12px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;

            &:hover {
              background-color: #deeafe;
              color: #333333;
            }
          }

          .screen-tag-blue {
            line-height: 17px;
            padding: 2px 9px;
            margin-right: 10px;
            color: #3f8cff;
            border: 1px solid #3f8cff;
            font-size: 14px;
            border-radius: 2px;
            display: flex;
            background-color: #f1f7ff;
            align-items: center;
            margin-bottom: 5px;
            .delete-icon {
              cursor: pointer;
              width: 11px;
              height: 11px;
              border-radius: 50%;
              background: #72b1f0;
              text-align: center;
              line-height: 9px;
              font-size: 10px;
              color: #fff;
              transform: scale(0.9);
              margin-left: 5px;

              &:hover {
                background: #2292ec;
                color: #fff;
              }
            }
          }

          .add-economy {
            cursor: pointer;
            line-height: 17px;
            padding: 2px 9px;
            margin-right: 30px;
            color: #3f8cff;
            border: 1px dashed #3f8cff;
            font-size: 14px;
            border-radius: 2px;
            display: flex;
            align-items: center;
            font-weight: bold;
            margin-bottom: 5px;
            &:hover {
              background-color: #f1f7ff;
            }
          }

          .screen-tag-active {
            background: #3a90ff !important;
            color: #fff !important;
          }
        }
      }

      .item-name {
        min-width: 80px;
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 20px;
      }

      .more-screen-box {
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        color: #3a90ff;
        font-size: 14px;
        margin-left: 10px;

        img {
          width: 20px;
          height: 20px;
          margin-right: 3px;
        }
      }
    }

    .artist-table {
      ::v-deep.el-checkbox .el-checkbox__inner {
        border-radius: 4px;
      }

      ::v-deep.el-table-column--selection .cell {
        padding-left: 14px;
      }
    }

    .footer-edit-btns {
      float: left;
      padding: 14px 0;
      display: flex;

      & > * {
        margin-right: 10px;
      }
    }

    ::v-deep.table-card {
      margin-top: 0;
      border: none;
      border-radius: 0;
    }
  }

  .right-search-body {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .upload-list-inline ::v-deep .ant-upload-list-item {
    float: left;
    width: 200px;
    margin-right: 8px;
  }

  .upload-list-inline ::v-deep .ant-upload-animate-enter {
    animation-name: uploadAnimateInlineIn;
  }

  .upload-list-inline ::v-deep .ant-upload-animate-leave {
    animation-name: uploadAnimateInlineOut;
  }

  .ywk ::v-deep .ant-upload-list {
    display: none !important;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    color: rgba(0, 0, 0, 0.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    list-style: none;
    font-feature-settings: 'tnum';
    zoom: 1;
  }

  .ywk1 ::v-deep .el-input__inner {
    -webkit-appearance: none;
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #d9d9d9;
    box-sizing: border-box;
    color: #333;
    display: inline-block;
    font-size: inherit;
    height: 30px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 100%;
  }

  .ywk {
    width: 370px;
  }

  .ywk ::v-deep .el-form-item__label {
    width: 130px !important;
  }

  /* .el-range__icon {
    display: none;
  } */
  /* .ywk  ::v-deep .el-input--prefix .el-input__inner {
    padding-left: 15px;
}
 .ywk2  ::v-deep .el-input--prefix .el-input__inner {
    padding-left: 15px;
} */
  /* .ywk ::v-deep.el-input__prefix, .el-input__suffix {
    top: 0;
    height: 100%;
    color: #C0C4CC;
    text-align: right;
    right: 0px !important
}
.ywk2 ::v-deep.el-input__prefix, .el-input__suffix {
    position: absolute !important;
    top: -1;
    height: 100%;
    color: #C0C4CC;
    text-align: right;
    right: 0px !important
} */
  // .add_btn {
  //   margin-bottom: 10px;
  //   background: #6bd9ba;
  //   border: none;
  // }
  // .add_btn:hover {
  //   background: #20ae71;
  // }
  /* .visab_hidden{
    position: fixed;
    z-index: -999;
} */
</style>

<style lang="scss">
  .account-table-popover {
    background-color: #fff;
    padding: 0 !important;
  }
</style>
